package com.xgk.boot.module.core.enums.biz;

import cn.hutool.core.util.ArrayUtil;
import com.xgk.boot.framework.common.core.ArrayValuable;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * 同步状态状态枚举
 * 同步状态：0-未同步 1-已同步 2-同步失败
 * @author dhb52
 */
@Getter
@AllArgsConstructor
public enum SyncStatusEnum implements ArrayValuable<Integer> {

    NOT_SYNC(0, "not_sync"),
    SYNC(1, "synchronized"),
    SYNC_FAILED(2, "sync_failed");

    public static final Integer[] ARRAYS = Arrays.stream(values()).map(SyncStatusEnum::getValue).toArray(Integer[]::new);

    /**
     * 类型
     */
    private final Integer value;
    /**
     * 名称
     */
    private final String name;

    @Override
    public Integer[] array() {
        return ARRAYS;
    }

    public static SyncStatusEnum valueOf(Integer interval) {
        return ArrayUtil.firstMatch(item -> item.getValue().equals(interval), SyncStatusEnum.values());
    }

}